package com.zyw.zhuangdian.pojo;

import com.zyw.zhuangdian.enums.MsgCode;
import com.zyw.zhuangdian.pojo.dto.PageDto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Resp<T> extends PageDto {

    private String code = MsgCode.MSG_SUCCESS.getCode();
    private String msg = MsgCode.MSG_SUCCESS.getMsg();
    private T data;

    public Resp(MsgCode msgCode) {
        this.code = msgCode.getCode();
        this.msg = msgCode.getMsg();
        this.data = null;
    }
    public boolean hasData(){
        if(data == null){
            return false;
        }
        return !(data instanceof List) || ((List<?>) data).size() != 0;
    }
    public boolean hasNoData(){
        return !hasData();
    }
}

